﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using DocumentManagement.ViewsModels;
using DocumentManagement.Models;
using Microsoft.Win32;
using System.IO;

namespace DocumentManagement.Views
{
    /// <summary>
    /// Interaction logic for ShowItemFileCreate.xaml
    /// </summary>
    public partial class ShowItemFileCreate : Window
    {
        ShowItemFileCreateViewsModel _showItemFileCreateViewsModel;
        public ShowItemFileCreate(CreateSend createSend)
        {
            InitializeComponent();
            _showItemFileCreateViewsModel = this.Resources["showItemFileCreateViewsModel"] as ShowItemFileCreateViewsModel;
            _showItemFileCreateViewsModel.MyCreateSend = createSend;

            dataGrid1.ItemsSource = createSend.CreateSendAttacheds.Where(p => p.Active == true).ToList();
           

        }
        private void DG_HyperlinkCreate_Click(object sender, RoutedEventArgs e)
        {
            TextBlock textblock = sender as TextBlock;
            var createsend = textblock.DataContext as CreateSendAttached;

            string fileName = "D:\\uploadCreateSend\\";
            SaveFileDialog save = new SaveFileDialog();
            save.FileName = createsend.FileAttached;
            save.Filter = "Image files (*.jpg)|*.jpg|Acrobat (*.pdf)| *.pdf|All files (*.*)|*.*";
            var result = save.ShowDialog(); // showdialog มันจะ return true กับ false
            if (result != null)
            {
                if (File.Exists(fileName + createsend.FileAttached))
                    File.Copy(fileName + createsend.FileAttached, save.FileName, true);
                else
                    MessageBox.Show("File not found");
            }

        }
      
    }
}
